﻿<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <!-- Data definition -->

  <xs:simpleType name="objectParent">
    <xs:restriction base="xs:string">
      <xs:enumeration value="NamedObject" />
      <xs:enumeration value="BasicObject" />      
      <xs:enumeration value="object" />
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="datatype">
    <xs:restriction base="xs:string">
      <xs:enumeration value="string" />
      <xs:enumeration value="text" />
      <xs:enumeration value="integer" />
      <xs:enumeration value="boolean" />
      <xs:enumeration value="dateTime" />
      <xs:enumeration value="uri" />
      <xs:enumeration value="guid" />
      <xs:enumeration value="image" />
      <xs:enumeration value="color" />
      <xs:enumeration value="byteArray" />
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="visibility">
    <xs:restriction base="xs:string">
      <xs:enumeration value="public" />
      <xs:enumeration value="protected" />
      <xs:enumeration value="internal" />
      <xs:enumeration value="private" />
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="interface">
    <xs:restriction base="xs:string">
      <xs:enumeration value="IBlob" />
      <xs:enumeration value="ISecurityPrincipal" />
      <xs:enumeration value="ISecurityCredential" />
      <xs:enumeration value="ISecurityCredentialCollection" />
    </xs:restriction>
  </xs:simpleType>
  
  <xs:complexType name="Field">
    <xs:sequence minOccurs="0" maxOccurs="unbounded">
      <xs:element name="Documentation" type="Documentation" minOccurs="0" maxOccurs="1" />
    </xs:sequence>
    <xs:attribute name="name" type="xs:string" use="required" />
    <xs:attribute name="type" type="datatype" use="required" />
    <xs:attribute name="storeAs" type="xs:string" use="optional" />
    <xs:attribute name="required" type="xs:boolean" use="optional" />
  </xs:complexType>

  <xs:complexType name="Reference">
    <xs:attribute name="name" type="xs:string" use="required" />
    <xs:attribute name="object" type="xs:string" use="required" />
    <xs:attribute name="storeAs" type="xs:string" use="optional" />
    <xs:attribute name="required" type="xs:boolean" use="optional" />
    <xs:attribute name="twoWay" type="xs:boolean" use="optional" />
    <xs:attribute name="revName" type="xs:string" use="optional" />
    <xs:attribute name="visibility" type="visibility" use="optional" />
    <xs:attribute name="revVisibility" type="visibility" use="optional" />
  </xs:complexType>

  <xs:complexType name="Enum">
    <xs:sequence minOccurs="0" maxOccurs="unbounded">
      <xs:element name="Documentation" type="Documentation" minOccurs="0" maxOccurs="1" />
      <xs:element name="Value" type="xs:string" />
    </xs:sequence>
    <xs:attribute name="name" type="xs:string" use="required" />
    <xs:attribute name="enum" type="xs:string" use="required" />
    <xs:attribute name="storeAs" type="xs:string" use="optional" />
    <xs:attribute name="required" type="xs:boolean" use="optional" />
  </xs:complexType>

  <xs:complexType name="Object">
    <xs:sequence>      
      <xs:element name="SecurityPrincipal" type="SecurityPrincipal" minOccurs="0" maxOccurs="1" />
      <xs:element name="Securable" type="Securable" minOccurs="0" maxOccurs="1" />
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="Implements" type="Implements"/>
        <xs:element name="CollImplements" type="CollImplements"/>
        <xs:element name="Field" type="Field" />
        <xs:element name="Reference" type="Reference" />
        <xs:element name="Enum" type="Enum" />
        <xs:element name="SecurityPrincipalRef" type="SecurityPrincipalRef" />
      </xs:choice>
    </xs:sequence>
    <xs:attribute name="name" type="xs:string" use="required" />
    <xs:attribute name="parent" type="objectParent" use="optional" />
    <xs:attribute name="visibility" type="visibility" use="optional" />
    <xs:attribute name="versioned" type="xs:boolean" use="optional" />
    <xs:attribute name="bindable" type="xs:boolean" use="optional" />
  </xs:complexType>

  <xs:complexType name="Relation">
    <xs:sequence minOccurs="0" maxOccurs="unbounded">
      <xs:element name="SecurityRelation" type="SecurityRelation" minOccurs="0" maxOccurs="1" />
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="Field" type="Field" />
        <xs:element name="Reference" type="Reference" />
        <xs:element name="Enum" type="Enum" />
      </xs:choice>
    </xs:sequence>
    <xs:attribute name="one" type="xs:string" use="required" />
    <xs:attribute name="oneName" type="xs:string" use="optional" />
    <xs:attribute name="two" type="xs:string" use="required" />
    <xs:attribute name="twoName" type="xs:string" use="optional" />
    <xs:attribute name="twoWay" type="xs:boolean" use="optional" />
    <xs:attribute name="object" type="xs:string" use="optional" />
    <xs:attribute name="visibility" type="visibility" use="optional" />
  </xs:complexType>

  <xs:complexType name="Documentation">
    <xs:sequence>
      <xs:element name="Summary" type="xs:string" minOccurs="0" maxOccurs="1" />
      <xs:element name="Detailed" type="xs:string" minOccurs="0" maxOccurs="1" />
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="Implements">
    <xs:attribute name="interface" type="interface" use="required" />
  </xs:complexType>

  <xs:complexType name="CollImplements">
    <xs:attribute name="interface" type="interface" use="required" />
  </xs:complexType>

  <!-- Settings management -->

  <xs:complexType name="Setting">
    <xs:attribute name="name" type="xs:string" use="required" />
    <xs:attribute name="type" type="datatype" use="required" />

    <!-- Text to be displayed if localized resource is missing -->
    <xs:attribute name="uiLocResource" type="xs:string" />
    <!-- Text to display if localized resource cannot be found (or a default resource is missing from the system) -->
    <xs:attribute name="uiNolocResourceText" type="xs:string" />
  </xs:complexType>

  <xs:complexType name="GlobalSettings">
    <xs:sequence maxOccurs="unbounded">
      <xs:element name="Setting" type="Setting" />
    </xs:sequence>
  </xs:complexType>

  <!-- Security implementation -->

  <xs:simpleType name="securityprincipaltype">
    <xs:restriction base="xs:string">
      <xs:enumeration value="user" />
      <xs:enumeration value="userGroup" />
      <xs:enumeration value="custom" />
    </xs:restriction>
  </xs:simpleType>
  <xs:complexType name="SecurityPrincipal">
    <xs:attribute name="type" type="securityprincipaltype" use="required" />
  </xs:complexType>

  <xs:complexType name="SecurityPrincipalRef">
    <xs:attribute name="name" type="xs:string" use="required" />
    <xs:attribute name="storeAs" type="xs:string" use="optional" />
    <xs:attribute name="required" type="xs:boolean" use="optional" />
    <xs:attribute name="twoWay" type="xs:boolean" use="optional" />
    <xs:attribute name="revName" type="xs:string" use="optional" />
    <xs:attribute name="visibility" type="visibility" use="optional" />
    <xs:attribute name="revVisibility" type="visibility" use="optional" />
  </xs:complexType>

  <xs:complexType name="Securable">
    <xs:sequence maxOccurs="unbounded">
      <xs:element name="Permission" type="Permission" />
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="AllowDenyRights" />

  <xs:simpleType name="permissiontype">
    <xs:restriction base="xs:string">
      <xs:enumeration value="allowDenyRight" />
      <xs:enumeration value="custom" />
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="roletype">
    <xs:restriction base="xs:string">
      <xs:enumeration value="builtinAdmins" />
      <xs:enumeration value="builtinUsers" />
      <xs:enumeration value="builtinGuests" />
      <xs:enumeration value="builtinServices" />
      <xs:enumeration value="custom" />
    </xs:restriction>
  </xs:simpleType>

  <xs:complexType name="Right" mixed="true">
    <!-- Text to be displayed if localized resource is missing -->
    <xs:attribute name="uiLocResource" type="xs:string" />
    <!-- Text to display if localized resource cannot be found (or a default resource is missing from the system) -->
    <xs:attribute name="uiNolocResourceText" type="xs:string" />
  </xs:complexType>
  <xs:complexType name="Permission">
    <xs:sequence minOccurs="0" maxOccurs="unbounded">
      <xs:element name="Right" type="Right" />
    </xs:sequence>
    <xs:attribute name="name" type="xs:string" use="required" />
    <xs:attribute name="type" type="permissiontype" use="required" />
    <!-- Text to be displayed if localized resource is missing -->
    <xs:attribute name="uiLocResource" type="xs:string" />
    <!-- Text to display if localized resource cannot be found (or a default resource is missing from the system) -->
    <xs:attribute name="uiNolocResourceText" type="xs:string" />
  </xs:complexType>

  <xs:complexType name="SecurityRelation" />

  <xs:complexType name="Policy">
    <xs:attribute name="name" type="xs:string" use="required" />
    <xs:attribute name="type" type="datatype" use="required" />

    <!-- Text to be displayed if localized resource is missing -->
    <xs:attribute name="uiLocResource" type="xs:string" />
    <!-- Text to display if localized resource cannot be found (or a default resource is missing from the system) -->
    <xs:attribute name="uiNolocResourceText" type="xs:string" />
  </xs:complexType>

  <xs:complexType name="Role">
    <xs:attribute name="name" type="xs:string" use="required" />
    <xs:attribute name="type" type="roletype" use="required" />

    <!-- Text to be displayed if localized resource is missing -->
    <xs:attribute name="uiLocResource" type="xs:string" />
    <!-- Text to display if localized resource cannot be found (or a default resource is missing from the system) -->
    <xs:attribute name="uiNolocResourceText" type="xs:string" />
  </xs:complexType>

  <xs:complexType name="SystemPolicy">
    <xs:sequence>
      <xs:choice minOccurs="1" maxOccurs="unbounded">
        <xs:element name="Policy" type="Policy" minOccurs="0" maxOccurs="1" />
        <xs:element name="Role" type="Role" minOccurs="0" maxOccurs="1" />
      </xs:choice>
    </xs:sequence>
  </xs:complexType>


  <!-- Schema definition -->

  <xs:element name="DataLayout">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Imports" minOccurs="0">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Import" type="xs:string" minOccurs="1" maxOccurs="unbounded" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="SystemPolicy" type="SystemPolicy" minOccurs="0" maxOccurs="1" />
        <xs:element name="GlobalSettings" type="GlobalSettings" minOccurs="0" maxOccurs="1" />
        <xs:element name="Objects">
          <xs:complexType>
            <xs:sequence>
              <xs:element maxOccurs="unbounded" name="Object" type="Object" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="Relations" minOccurs="0">
          <xs:complexType>
            <xs:sequence>
              <xs:element minOccurs="0" maxOccurs="unbounded" name="Relation" type="Relation" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
      <xs:attribute name="namespace" type="xs:string" use="optional" />
      <xs:attribute name="name" type="xs:string" use="required" />
      <xs:attribute name="dependsOnLayout" type="xs:string" use="optional" />
    </xs:complexType>
  </xs:element>
</xs:schema>